package org.cbg.panel;

import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

import org.cbg.btn.CBGSellBtn;
import org.cbg.btn.TrslationBtn;
import org.cbg.entity.Salegoods;
import org.cbg.until.TraslationTableRuleUntil;
import org.come.entity.RoleSummoning;
import org.come.until.CutButtonImage;

import com.tool.Document.NumberDocument;
import com.tool.tcpimg.UIUtils;



/**
 * 我要卖 寄售商品面板
 *
 * @author Administrator
 *
 */
public class TraslationWantSendJishoushangpinJpanel extends JPanel {
    /** 物品 ， 灵宝， 召唤兽,图片 */
    private JLabel tupian;
    private TrslationBtn wupin, lingbao, zhaohuanshou;
    /** 寄售价格，价格确认，指定ID购买 */
    private JTextField sale, confirm, assignID;
    /** 多选框 上架7天 ,指定ID购买 */
    private JLabel time, buyId;
    /** 确认寄售按钮 */
    private CBGSellBtn sendOk;
    private JScrollPane jScrollPane;
    private JTextArea area;
    private TraslationWantSendJishoushangpinFenleiJpanel traslationWantSendJishoushangpinFenleiJpanel;
    private Salegoods salegoods;

    public TraslationWantSendJishoushangpinJpanel() {
        // TODO Auto-generated constructor stub
        this.setBackground(null);
        this.setOpaque(false);
        this.setLayout(null);



        traslationWantSendJishoushangpinFenleiJpanel = new TraslationWantSendJishoushangpinFenleiJpanel();
        this.add(traslationWantSendJishoushangpinFenleiJpanel);

        wupin = new TrslationBtn("inkImg/number/b4/jsB01a.png", 1);
        wupin.setBounds(30, 10+18, 40, 83);
        this.add(wupin);

        lingbao = new TrslationBtn("inkImg/number/b4/jsB02.png", 1);
        lingbao.setBounds(30, 88+18, 40, 83);
        this.add(lingbao);

        zhaohuanshou = new TrslationBtn("inkImg/number/b4/jsB03.png", 1);
        zhaohuanshou.setBounds(30, 166+18, 40, 83);
        this.add(zhaohuanshou);

        tupian = new JLabel();
        tupian.setBackground(null);
        tupian.setBounds(587, 32, 45, 45);
        tupian.setOpaque(false);
        tupian.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                // TODO Auto-generated method stub
                thGood(null);
            }
        });
        this.add(tupian);

        /** 输入框 */
        wupin.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                try {
                    wupin.setIcons(CutButtonImage.cuts("inkImg/number/b4/jsB01a.png"));
                    lingbao.setIcons(CutButtonImage.cuts("inkImg/number/b4/jsB02.png"));
                    zhaohuanshou.setIcons(CutButtonImage.cuts("inkImg/number/b4/jsB03.png"));
                } catch (Exception e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
                traslationWantSendJishoushangpinFenleiJpanel.change(0);
            }
        });
        lingbao.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                try {
                    lingbao.setIcons(CutButtonImage.cuts("inkImg/number/b4/jsB02a.png"));
                    wupin.setIcons(CutButtonImage.cuts("inkImg/number/b4/jsB01.png"));
                    zhaohuanshou.setIcons(CutButtonImage.cuts("inkImg/number/b4/jsB03.png"));
                } catch (Exception e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
                traslationWantSendJishoushangpinFenleiJpanel.change(1);

            }
        });
        zhaohuanshou.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                try {
                    zhaohuanshou.setIcons(CutButtonImage.cuts("inkImg/number/b4/jsB03a.png"));
                    wupin.setIcons(CutButtonImage.cuts("inkImg/number/b4/jsB01.png"));
                    lingbao.setIcons(CutButtonImage.cuts("inkImg/number/b4/jsB02.png"));
                } catch (Exception e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
                traslationWantSendJishoushangpinFenleiJpanel.change(2);
            }
        });
        /** 多选框设计sale , confirm ,assignID */
        sale = new JTextField();
        sale.setBounds(566, 103, 128, 18);
        sale.setOpaque(false);
        sale.setBorder(null);
        sale.setForeground(Color.white);
        sale.setCaretColor(Color.white);
        sale.setFont(UIUtils.TEXT_FONT1);
        sale.setDocument(new NumberDocument(sale, 7));
        this.add(sale);

        confirm = new JTextField();
        confirm.setBounds(566, 129, 128, 18);
        confirm.setOpaque(false);
        confirm.setBorder(null);
        confirm.setForeground(Color.white);
        confirm.setCaretColor(Color.white);
        confirm.setFont(UIUtils.TEXT_FONT1);
        confirm.setDocument(new NumberDocument(confirm, 7));
        this.add(confirm);

        assignID = new JTextField();
        assignID.setBounds(518, 228, 128, 18);
        assignID.setOpaque(false);
        assignID.setBorder(null);
        assignID.setForeground(Color.white);
        assignID.setCaretColor(Color.white);
        assignID.setFont(UIUtils.TEXT_FONT1);
        assignID.setDocument(new NumberDocument(assignID, 7));
        this.add(assignID);

        /** 多选框 time，buyId */
        time = new JLabel();
        time.setBounds(498, 180, 13, 13);
        time.setBorder(null);
        time.setOpaque(false);
//        time.setIcon(CutButtonImage.getImage("skin/8100226/button/13.png", -1, -1));
        this.add(time);

        buyId = new JLabel();
        buyId.setBounds(498, 204, 15, 15);
        buyId.setBorder(null);
        buyId.setOpaque(false);
        buyId.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                // TODO Auto-generated method stub
                if (buyId.getIcon() == null) {
                    buyId.setIcon(CutButtonImage.getImage("skin/8100226/button/13.png", -1, -1));
                } else {
                    buyId.setIcon(null);
                }
            }
        });
        this.add(buyId);

        sendOk = new CBGSellBtn("inkImg/number/b4/qrjs.png", 1, UIUtils.COLOR_BTNPUTONG, UIUtils.TEXT_HY16, "", this);
        sendOk.setBounds(565, 390, 105, 33);
        this.add(sendOk);

        jScrollPane = new JScrollPane();
        area = new JTextArea();
        area.append("1、上架需要缴纳寄售价格的2%的仙玉;\n");
        area.append("2、寄售价格在100仙玉-100000000仙玉之间。");
        area.setBounds(66, 0, 395, 135);
        area.setForeground(UIUtils.COLOR_cbg6);
        area.setFont(new Font("宋体", Font.PLAIN, 12));
        area.setOpaque(false);
        TraslationTableRuleUntil.TableModel(jScrollPane, area);
        jScrollPane.getVerticalScrollBar().setUnitIncrement(30);
        jScrollPane.setBounds(2, 280, 395, 135);
        this.add(jScrollPane);
    }

    /***/
    private ImageIcon icon;

    @Override
    protected void paintComponent(Graphics g) {
        // TODO Auto-generated method stub
        super.paintComponent(g);
        if (icon == null) {
            icon = new ImageIcon("inkImg/number/b4/wpzjm.png");
        }
        g.drawImage(icon.getImage(), 15, 20, 731, 410, this);


    }

    /** 替换上架商品 */
    public void thGood(Salegoods salegoods) {
        this.salegoods = salegoods;
        if (salegoods == null) {
            tupian.setIcon(null);
        } else {// 2大话币，3道具，5装备，6灵宝，4召唤兽
            tupian.setIcon(CutButtonImage.getCBG(salegoods.getSaletype(), salegoods.getSaleskin(), 46, 46));
        }
        sale.setText("");
        confirm.setText("");
        assignID.setText("");
    }

    public Salegoods getSalegoods() {
        return salegoods;
    }

    public void setSalegoods(Salegoods salegoods) {
        this.salegoods = salegoods;
    }

    public BigDecimal getJG() {
        BigDecimal j1 = ((NumberDocument) sale.getDocument()).getNum();
        BigDecimal j2 = ((NumberDocument) confirm.getDocument()).getNum();
        if (j1.compareTo(j2) == 0) {
            return j1;
        }
        return null;
    }

    public BigDecimal getZD() {
        if (buyId.getIcon() != null) {
            BigDecimal j1 = ((NumberDocument) assignID.getDocument()).getNum();
            return j1;
        }
        return new BigDecimal(0);
    }

    public void qkPet(RoleSummoning pet) {
        traslationWantSendJishoushangpinFenleiJpanel.getTraslationWantSendJishoushangpinFenleiZhaohuanshouJpanel()
                .chang(pet, false);
    }
}
